/*
 * Copyright 2012-2025 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.assertj.tests.core.description;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.description.Description.mostRelevantDescription;

import org.assertj.core.description.Description;
import org.assertj.core.description.TextDescription;
import org.junit.jupiter.api.Test;

class Description_mostRelevantDescription_Test {

  @Test
  void should_return_exsiting_description_if_not_empty() {
    // GIVEN
    String existing = "bar";
    Description description = new TextDescription(existing);
    // WHEN
    String mostRelevantDescription = mostRelevantDescription(description, "foo");

    // THEN
    assertThat(mostRelevantDescription).isEqualTo(existing);
  }

  @Test
  void should_return_the_other_value_if_description_value_is_empty() {
    // GIVEN
    Description description = new TextDescription("");
    String other = "foo";

    // WHEN
    String mostRelevantDescription = mostRelevantDescription(description, other);

    // THEN
    assertThat(mostRelevantDescription).isEqualTo(other);
  }

  @Test
  void should_return_the_other_value_if_description_value_is_null() {
    // GIVEN
    Description description = new TextDescription(null);
    String other = "foo";

    // WHEN
    String mostRelevantDescription = mostRelevantDescription(description, other);

    // THEN
    assertThat(mostRelevantDescription).isEqualTo(other);
  }

  @Test
  void should_return_the_other_value_if_null() {
    // GIVEN
    Description description = null;
    String other = "foo";

    // WHEN
    String mostRelevantDescription = mostRelevantDescription(description, other);

    // THEN
    assertThat(mostRelevantDescription).isEqualTo(other);
  }

}
